<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="//unpkg.com/element-plus"></script>
    <script src="//unpkg.com/@element-plus/icons-vue"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        /* 样式 */
        .login-page {
            height: 100vh;
            background-color: rgb(201, 228, 236);
        }
        .login-page .el-form {
            margin-top: 180px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            user-select: none;

        }
        .login-page .el-form .title {
            margin: 0 auto;
        }
        .login-page .el-form .button {
            width: 100%;
        }

        .login-page .el-form .flex {
            width: 100%;
            display: flex;
            justify-content: space-between;
        }
        .login-page .logo{
            background: url('../images/sufei.jpg') no-repeat center;
            border-radius: 0 20px 20px 0;
        }
    </style>
</head>
<body>
    <div id="app">
        <el-row class="login-page">
            <el-col :span="12" class="logo"></el-col>
            <el-col :span="6" :offset="3" class="form">
                <!-- 账号登录 -->
                <el-form ref="form" size="large" autocomplete="off">
                    <el-form-item>
                        <h1>账号登陆</h1>
                    </el-form-item>
                    <el-form-item >
                        <el-input :prefix-icon="User" v-model="username" placeholder="请输入用户名"></el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input :prefix-icon="Lock" type="password" v-model="password" placeholder="请输入密码"></el-input>
                    </el-form-item>
                    <el-form-item class="flex">
                        <div class="flex">
                            <el-checkbox>记住我</el-checkbox>
                            <el-link type="primary" :underline="false">忘记密码？</el-link>
                        </div>
                    </el-form-item>
                    <!-- 登录按钮 -->
                    <el-form-item>
                        <el-button class="button" type="primary" auto-insert-space @click="loginByAccount()">登录
                        </el-button>
                    </el-form-item>
                    <el-form-item class="flex">
                        <el-link type="info" :underline="false" @click="isAccount = false;clearaccountData()">
                            ← 手机登录
                        </el-link>
                    </el-form-item>
                </el-form>
                <!-- 手机验证码登录表单 -->

            </el-col>
        </el-row>
    </div>

    <script>
        const {createApp, ref} = Vue
        const {ElMessage, ElMessageBox} = ElementPlus
        const vm = createApp({
            data() {
                return {
                    username: '',
                    password: ''
                }
            },
            methods: {
                async loginByAccount(){
                    const params = new URLSearchParams()
                    params.append('username', this.username)
                    params.append('password', this.password)
                    const {data: resp} = await axios.post(`http://localhost/admin/administrators/login`, params,{
                        withCredentials: true
                    })
                    if(resp.status === 'SUCCESS'){
                        //将登录用户名存入到本地
                        localStorage.setItem("username", resp.data)
                        window.location = `index.html`
                    }
                }
            }
        })
        for ([name, comp] of Object.entries(ElementPlusIconsVue)) {
            vm.component(name, comp);
        }
        vm.use(ElementPlus)
        vm.mount("#app")

    </script>
</body>

</html>